#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int p[N];
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
int n, m;
int main()
{
	cin >> n >> m;
	for (int i = 1; i < N; i++) {
		p[i] = i;
	}
	while (m--) {
		int a, b, k;
		cin >> k >> a;
		if (k == 1) {
			cin >> b;
			p[find(a)] = find(b);
		}
		else {
			cout << find(a) << endl;
		}
		
	}
	return 0;
}